﻿<cfcomponent output="false" implements="com.cargopooling.apollo.listener.ApplicationFrameworkListener">

	<cffunction name="init" access="public" output="false" returntype="PlugInManager">
		<cfargument name="modelGlueLoader" type="ModelGlue.gesture.module.XMLModuleLoader" required="true" />
		<cfargument name="coldSpringLoader" type="it.millemultimedia.easyBlog.util.XMLColdSpringLoader" required="true" />
		<cfargument name="pluginRoot" type="String" required="true" />
		<cfargument name="pluginDB" type="String" required="true" />
		
		<cfset variables.modelGlueLoader = arguments.modelGlueLoader />
		<cfset variables.coldSpringLoader = arguments.coldSpringLoader />
		<cfset variables.pluginRoot = arguments.pluginRoot />
		<cfset variables.pluginDB = arguments.pluginDB />		
		
		<cfreturn this/>
	</cffunction>
	
	<cffunction name="onApplicationStart" access="public" output="false" returntype="void">
		<cfset load( argumentCollection=arguments ) />
	</cffunction>
    
    <cffunction name="onRequestStart" access="public" output="false" returntype="void">
		
	</cffunction>
    
    <cffunction name="onRequestEnd" access="public" output="false" returntype="void">
		
	</cffunction>
    
    <cffunction name="onSessionStart" access="public" output="false" returntype="void">
		
	</cffunction>
    
    <cffunction name="onSessionEnd" access="public" output="false" returntype="void">
		
	</cffunction>
	
	<cffunction name="load" access="private" output="false" returntype="void" >
		<cfargument name="modelGlue" type="ModelGlue.gesture.ModelGlue" required="true" hint="ModelGlue framework instance." />
		<cfargument name="cargoPooling" type="it.millemultimedia.easyBlog.core.CargoPooling" required="true" />
		
		<cfset var plugInConfig = structNew() />
		<cfset var configPath = "" />
		<cfset var plugin = 0 />
		<cfset var root = expandPath( variables.pluginRoot ) />
		<cfset var lib = deserializeJSON( fileRead( expandPath( variables.pluginDB ) ) ) />
		<cfset var i = structNew() />
		
		<cfloop array="#lib#" index="i">
		
			<cfset configPath = expandPath( root & i.name & "/" & "config/" ) />
		
			<cfif directoryExists( configPath ) >
			
				<cfif fileExists( configPath & "ColdSpring.xml" ) >
				
					<!--- load business plugin --->
					<cfset variables.coldSpringLoader.load( arguments.cargoPooling, configPath & "ColdSpring.xml" ) />
				
				</cfif>
				
				<cfif fileExists( configPath & "ModelGlue.xml" ) >
				
					<!--- load presentation plugin --->
					<cfset variables.modelGlueLoader.load( arguments.modelGlue, configPath & "ModelGlue.xml", structNew() ) />
				
				</cfif>
			
			</cfif>
		
		</cfloop>
		
	</cffunction>
	
	<!---
	not implemented
	<cffunction name="install" access="public" returntype="void" output="false">
    	<cfargument name="name" type="String" required="true" />
		
    	<cfset var root = expandPath( variables.pluginRoot ) />
		<cfset var configPath = "" />
		<cfset var plugInConfig = "" />
		
		
		
		<cfset configPath = expandPath( root & name & "/" & "config/" ) />
		
    	<cfif fileExists( configPath & "Plugin.xml" )>
				
			<cfset plugInConfig = xmlParse( configPath & "Plugin.xml" ) />
		
		</cfif>
			
    </cffunction>
    --->
	
	

</cfcomponent>